﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Order_ConfirmOrder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["cacheId"] != null)
        {
            CacheId.Value = Request.QueryString["cacheId"];
            FillFormByObjectCache();
        }
    }

    protected void Confirm_Click(object sender, EventArgs e)
    {
        if (CacheId.Value != null)
        {
            Response.Redirect("BuildOrder.aspx?cacheId=" + CacheId.Value);
        }
    }

    protected void PreviousStep_Click(object sender, EventArgs e)
    {
        if (CacheId.Value != null)
        {
            Response.Redirect("MakeOrder.aspx?cacheId=" + CacheId.Value);
        }
    }

    private void FillFormByObjectCache()
    {
        var order = ObjectCacheHelper.GetObjectCache<OrderInfo>(CacheId.Value);

        if (order != null)
        {
            EnglishName.Text = order.EnglishCompanyName;
            ChineseName.Text = order.ChineseCompanyName;
            CompanyID.Text = order.CompanyID;
            RegisterRegion.Text = new RegionBLL().GetRegionNameByRegionID(order.RegisterRegionID);
            Stock.Text = order.RegisterStock.ToString();
            RegisterDate.Text = order.RegisiterDate.ToString("yyyy-MM-dd");

            ClientName.Text = order.ClientName;
            Telephone.Text = order.Telephone;
            Mobile.Text = order.Mobile;
            Address.Text = order.Address;
            Email.Text = order.Email;
            IM.Text = order.IM;
            Fax.Text = order.Fax;
            ClientType.Text = RemarkAttribute.GetEnumRemark(order.ClientType);

            OrderTime.Text = order.OrderTime.ToString("yyyy-MM-dd");
            Amount.Text = order.Amount.ToString();
            CurrencyType.Text = RemarkAttribute.GetEnumRemark(order.CurrencyType);
            Branch.Text = new BranchBLL().GetBranchNameByBranchID(order.BranchID);
            Empolyee.Text = new EmpolyeeBLL().GetEmpolyeeNameByEmpolyeeID(order.EmpolyeeID);
            DelegateType.Text = new DelegateBLL().GetDelegateNameByDelegateType(order.DelegateTypeID);

            if (order.DelegateTypeID == 4)
            {
                AuditYear.Visible = true;
                AuditYear.Text = "年检到" + order.AuditYear + "年";
            }

            Remark.Text = order.Remark;

            Label1.Text = order.IsSubsidiary.ToString();
            Label2.Text = order.ParentCompanyID;


            if(order.DelegateTypeID == 5)
            {
                txtBr.Text = order.BR;
                txtBusinessAddress.Text = order.BusinessAddress;
                txtBusinessScope.Text = order.BusinessScope;
                txtEndTime.Text = order.EndTime.ToString("yyyy-MM-dd");
                txtStartTime.Text = order.StartTime.ToString("yyyy-MM-dd");
                txtTotalTurnover.Text = order.TotalTurnover.ToString();
                txtProfitTax.Text = order.ProfitTax.ToString();
                HeShuUl.Visible = true;
            }
        }
    }
}